package mediadisplay.ui 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.FocusEvent;
	import flash.events.MouseEvent;
	import flash.filters.DropShadowFilter;
	import flash.filters.GlowFilter;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	/**
	 * ...
	 * @author Anders Figenschow selvfølgelig
	 */
	public class TextArea extends Sprite
	{
		
		public var tf:TextField;
		public var tf2:TextField;
		private var textformat:TextFormat;
		private var textformat2:TextFormat;
		private var _desc:String;
		private var _isPassword:Boolean;
		
		public function TextArea(desc:String, isPassword:Boolean = false) 
		{
			_isPassword = isPassword;
			_desc = desc;
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			textformat = new TextFormat();
			textformat.color = 0x777777;
			textformat.size = 28;
			
			textformat2 = new TextFormat();
			textformat2.color = 0x000000;
			textformat2.size = 28;
			textformat2.align = TextFormatAlign.CENTER;
			
			graphics.lineStyle(1, 0, 1, true);
			graphics.beginFill(0xffffff, 0.7);
			graphics.drawRoundRect(0, 0, 500, 40, 10, 10);
			
			tf = new TextField();
			tf.defaultTextFormat = textformat;
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.text = _desc;
			tf.selectable = false;
			tf.mouseEnabled = false;
			tf.type = TextFieldType.DYNAMIC;
			
			
			tf2 = new TextField();
			addChild(tf2);
			addChild(tf);
			tf2.defaultTextFormat = textformat2;
			tf2.width = 500;
			tf2.x = 0;
			tf.y = tf2.y = 2;
			tf2.multiline = false;
			tf2.wordWrap = false;
			tf2.type = TextFieldType.INPUT;
			tf2.displayAsPassword = _isPassword;
			
			tf2.addEventListener(MouseEvent.CLICK, clickHandler);
			tf2.addEventListener(FocusEvent.FOCUS_IN, focusInHandler);
			tf2.addEventListener(FocusEvent.FOCUS_OUT, focusOutHandler);
			
			tf.x = tf2.width / 2 - tf.width / 2;
			
			cacheAsBitmap = true;
			
			filters = [new GlowFilter(0xffffff, 0.6, 8, 8, 2), new DropShadowFilter(4, 45, 0, 0.6)];
			
		}
		
		private function focusInHandler(e:FocusEvent):void 
		{
			tf.visible = false;			
		}
		
		public function focusOutHandler(e:FocusEvent = null):void 
		{
			if (tf2.text != "") return;
			tf.visible = true;
		}
		
		private function clickHandler(e:MouseEvent):void 
		{
			tf.visible = false;
		}
		public function getValue():String {
			return tf2.text;
		}
		public function setDescription(txt:String):void {
			tf.text = txt;
		}
		
	}

}